package com.fieldchain.ex.fa100.mvp.model;

import android.graphics.Bitmap;

import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.inter.ImageCallBack;
import com.fieldchain.ex.fa100.inter.IntegerCallBack;
import com.fieldchain.ex.fa100.mvp.base.MyBaseModel;
import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.ImageRequest;
import com.fieldchain.ex.fa100.utils.net.modle.StringRequest;
import com.fieldchain.ex.fa100.utils.screen.MyToast;

import java.util.HashMap;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/3
 */
public class RegistEmailModle extends MyBaseModel {

    public void regist(String userName, String smsCode, final IntegerCallBack integerCallBack) {
        if (smsCode.length() == 0) {
            MyToast.show("请输入邮箱验证码");
            return;
        }

        if (userName.length() == 0) {
            MyToast.show("请输入邮箱账号");
            return;
        }
        HashMap map = new HashMap();
        map.put("userName", userName);
        map.put("msgCode", smsCode);
        map.put("step", "1");
        HttpRequest.getInstance().postRequest(map, Constant.regist, new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                integerCallBack.index(code);
                if(code!=200) {
                    MyToast.show(msg);
                }
            }

            @Override
            public void onFaild(Exception e) {
                integerCallBack.index(505);
            }
        });
    }

    public void getVer(final ImageCallBack callBack) {
        HttpRequest.getInstance().getImage(Constant.image, new ImageRequest() {
            @Override
            public void imgReceive(Bitmap bit) {
                callBack.imageReceive(bit);
            }
        });
    }

    @Override
    public void detachView() {

    }

    public void regist(String userName, String smsCode, String pwd, String invite, final IntegerCallBack integerCallBack) {

        if (pwd.length() == 0) {
            MyToast.show("请输入密码");
            return;
        }
        HashMap map = new HashMap();
        map.put("userName", userName);
        map.put("password", pwd);
        map.put("inviteCode", invite);
        map.put("msgCode", smsCode);
        map.put("step", "2");
        HttpRequest.getInstance().postRequest(map, Constant.regist, new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                integerCallBack.index(code);
                if(code!=200) {
                    MyToast.show(msg);
                }
            }

            @Override
            public void onFaild(Exception e) {
                integerCallBack.index(505);
            }
        });
    }
}
